<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\mobilenode\controller;

class AdminUser extends \app\AdminRest
{
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
    }
    public function adminList()
    {
        $input = $this->_param;
        $admin_model = new \app\mobilenode\model\RoleAdmin();
        $dis[] = ["uniacid", "=", $this->_uniacid];
        $dis[] = ["status", ">", -1];
        if($this->_user["is_admin"] == 0) {
            $dis[] = ["admin_id", "=", $this->_user["admin_id"]];
        } else {
            $dis[] = ["admin_id", "=", 0];
        }
        $data = $admin_model->dataList($dis, $input["limit"]);
        if(!empty($data["data"])) {
            $user_model = new \app\massage\model\User();
            foreach ($data["data"] as &$v) {
                $v["phone"] = $user_model->where(["id" => $v["user_id"]])->value("phone");
            }
        }
        return $this->success($data);
    }
    public function adminAdd()
    {
        $input = $this->_input;
        $admin_model = new \app\mobilenode\model\RoleAdmin();
        $check = $admin_model->checkDatas($this->_uniacid, $input["user_id"], $this->_user);
        if(!empty($check["code"])) {
            $this->errorMsg($check["msg"]);
        }
        $insert = ["uniacid" => $this->_uniacid, "user_id" => $input["user_id"], "mobile" => $input["mobile"], "node" => implode(",", $input["node"])];
        if($this->_user["is_admin"] == 0) {
            $insert["admin_id"] = $this->_user["admin_id"];
        }
        $res = $admin_model->dataAdd($insert);
        return $this->success($res);
    }
    public function adminStatusUpdate()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        $admin_model = new \app\mobilenode\model\RoleAdmin();
        $res = $admin_model->dataUpdate($dis, $input);
        return $this->success($res);
    }
    public function adminUpdate()
    {
        $input = $this->_input;
        $admin_model = new \app\mobilenode\model\RoleAdmin();
        $dis = ["uniacid" => $this->_uniacid, "user_id" => $input["user_id"]];
        $find = $admin_model->where($dis)->where("id", "<>", $input["id"])->where("status", ">", -1)->find();
        if(!empty($find)) {
            $this->errorMsg("已经绑定过该用户");
        }
        $insert = ["uniacid" => $this->_uniacid, "user_id" => $input["user_id"], "node" => implode(",", $input["node"]), "mobile" => $input["mobile"]];
        $res = $admin_model->dataUpdate(["id" => $input["id"]], $insert);
        return $this->success($res);
    }
    public function adminInfo()
    {
        $input = $this->_param;
        $admin_model = new \app\mobilenode\model\RoleAdmin();
        $dis = ["id" => $input["id"]];
        $data = $admin_model->dataInfo($dis);
        return $this->success($data);
    }
}

?>